<!DOCTYPE html>

<html>
<head>
  <style>
    img {
        margin: 10px;
    }

    img {
        -webkit-animation-duration: 2s !important;
        -webkit-animation-timing-function: linear !important;
    }

    #grayscale-box {
        -webkit-filter: grayscale(1);
    }
    .animating #grayscale-box {
        -webkit-animation-name: grayscale-anim;
    }

    #sepia-box {
        -webkit-filter: sepia(1);
    }
    .animating #sepia-box {
        -webkit-animation: sepia-anim;
    }

    #saturate-box {
        -webkit-filter: saturate(1);
    }
    .animating #saturate-box {
        -webkit-animation: saturate-anim;
    }

    #huerotate-box {
        -webkit-filter: hue-rotate(90deg);
    }
    .animating #huerotate-box {
        -webkit-animation: huerotate-anim;
    }

    #invert-box {
        -webkit-filter: invert(1);
    }
    .animating #invert-box {
        -webkit-animation: invert-anim;
    }

    #opacity-box {
        -webkit-filter: opacity(0);
    }
    .animating #opacity-box {
        -webkit-animation: opacity-anim;
    }

    #brightness-box {
        -webkit-filter: brightness(0);
    }
    .animating #brightness-box {
        -webkit-animation: brightness-anim;
    }

    #contrast-box {
        -webkit-filter: contrast(0);
    }
    .animating #contrast-box {
        -webkit-animation: contrast-anim;
    }

    #blur-box {
        -webkit-filter: blur(10px);
    }
    .animating #blur-box {
        -webkit-animation: blur-anim;
    }

    @-webkit-keyframes grayscale-anim {
        from { -webkit-filter: grayscale(0); }
        to   { -webkit-filter: grayscale(1); }
    }

    @-webkit-keyframes sepia-anim {
        from { -webkit-filter: sepia(0); }
        to   { -webkit-filter: sepia(1); }
    }

    @-webkit-keyframes saturate-anim {
        from { -webkit-filter: saturate(0); }
        to   { -webkit-filter: saturate(1); }
    }

    @-webkit-keyframes huerotate-anim {
        from { -webkit-filter: hue-rotate(0); }
        to   { -webkit-filter: hue-rotate(180deg); }
    }

    @-webkit-keyframes invert-anim {
        from { -webkit-filter: invert(0); }
        to   { -webkit-filter: invert(1); }
    }

    @-webkit-keyframes opacity-anim {
        from { -webkit-filter: opacity(1); }
        to   { -webkit-filter: opacity(0); }
    }

    @-webkit-keyframes brightness-anim {
        from { -webkit-filter: brightness(1); }
        to   { -webkit-filter: brightness(0); }
    }

    @-webkit-keyframes contrast-anim {
        from { -webkit-filter: contrast(1); }
        to   { -webkit-filter: contrast(0); }
    }

    @-webkit-keyframes blur-anim {
        from { -webkit-filter: blur(0); }
        to   { -webkit-filter: blur(20px); }
    }

  </style>
  <script src="../../animations/resources/animation-test-helpers.js"></script>
  <script type="text/javascript">

    const preExpectedValues = [
        // [element-id, property, expected-value]
        ["grayscale-box", "webkitFilter", 'grayscale(1)'],
        ["sepia-box", "webkitFilter", 'sepia(1)'],
        ["saturate-box", "webkitFilter", 'saturate(1)'],
        ["huerotate-box", "webkitFilter", 'hue-rotate(90deg)'],
        ["invert-box", "webkitFilter", 'invert(1)'],
        ["opacity-box", "webkitFilter", 'opacity(0)'],
        ["brightness-box", "webkitFilter", 'brightness(0)'],
        ["contrast-box", "webkitFilter", 'contrast(0)'],
        ["blur-box", "webkitFilter", 'blur(10px)'],
    ];

    const expectedValues = [
        // [time, element-id, property, expected-value, tolerance]
        [1, "grayscale-box", "webkitFilter", 'grayscale(0.5)', 0.15],
        [1, "sepia-box", "webkitFilter", 'sepia(0.5)', 0.15],
        [1, "saturate-box", "webkitFilter", 'saturate(0.5)', 0.15],
        [1, "huerotate-box", "webkitFilter", 'hue-rotate(90deg)', 20],
        [1, "invert-box", "webkitFilter", 'invert(0.5)', 0.15],
        [1, "opacity-box", "webkitFilter", 'opacity(0.5)', 0.15],
        [1, "brightness-box", "webkitFilter", 'brightness(0.5)', 0.15],
        [1, "contrast-box", "webkitFilter", 'contrast(0.5)', 0.15],
        [1, "blur-box", "webkitFilter", 'blur(10px)', 4],
    ];

    function runPreTest() {
        for (var i=0; i < preExpectedValues.length; i++) {
            var id = preExpectedValues[i][0];
            var prop = preExpectedValues[i][1];
            var expected = preExpectedValues[i][2];
            var element = document.getElementById(id);
            var computedStyle = window.getComputedStyle(element)[prop];
            if (computedStyle == expected)
              result += "PASS: Element " + id + " had filter value " + expected + " before animation.<br>";
            else
              result += "FAIL: Element " + id + " had filter value " + computedStyle + " rather than " + expected + " before animation.<br>";
        }

        // Completed the pre-animation tests. Now start the animation.
        setTimeout(function () {
            document.body.className = "animating";
            runAnimationTest(expectedValues);
        }, 0);
    }

    if (window.testRunner) {
        testRunner.dumpAsText();
        testRunner.waitUntilDone();
    }

    window.addEventListener("load", runPreTest, false);
  </script>
</head>
<body>

<img src="resources/reference.png" id="grayscale-box">
<img src="resources/reference.png" id="sepia-box">
<img src="resources/reference.png" id="saturate-box">
<img src="resources/reference.png" id="huerotate-box">
<img src="resources/reference.png" id="invert-box">
<img src="resources/reference.png" id="opacity-box">
<img src="resources/reference.png" id="brightness-box">
<img src="resources/reference.png" id="contrast-box">
<img src="resources/reference.png" id="blur-box">

<!-- this result element is filled by the animation test system -->
<div id="result">
</div>
</body>
</html>
